import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'amfe-flexible'
import axios from 'axios'
import VueAxios from 'vue-axios'
import { Switch, Collapse, CollapseItem, CouponCell, CouponList, Rate, Tab, Uploader, AddressEdit, Area, Button, Calendar, Card, Cell, CellGroup, Checkbox, Col, CountDown, Divider, DropdownItem, DropdownMenu, Field, Form, Grid, GridItem, Icon, NavBar, NoticeBar, Popup, Radio, RadioGroup, Row, Search, Swipe, SwipeItem, Tabbar, TabbarItem, Tabs, Tag, Toast, Dialog } from 'vant';

import './assets/css/global.css'
import bus from './views/eventBus.js'

Vue.use(Switch);
Vue.prototype.bus = bus;
Vue.config.productionTip = false
Vue.use(VueAxios, axios)
Vue.use(Uploader)
Vue.use(Grid)
Vue.use(GridItem)
Vue.use(NavBar)
Vue.use(Tabbar)
Vue.use(TabbarItem)
Vue.use(Tabs)
Vue.use(Button)
Vue.use(Swipe)
Vue.use(SwipeItem)
Vue.use(AddressEdit)
Vue.use(Calendar)
Vue.use(Cell)
Vue.use(Col)
Vue.use(Row)
Vue.use(Area)
Vue.use(Popup)
Vue.use(Field)
Vue.use(NoticeBar)
Vue.use(Search)
Vue.use(Divider)
Vue.use(CellGroup)
Vue.use(Form)
Vue.use(Card)
Vue.use(Tag)
Vue.use(Checkbox)
Vue.use(CountDown)
Vue.use(Icon)
Vue.use(Radio)
Vue.use(RadioGroup)
Vue.use(DropdownMenu);
Vue.use(DropdownItem);
Vue.use(Toast);
Vue.use(Rate);
Vue.use(Collapse)
Vue.use(CollapseItem)
Vue.use(Tab)
Vue.use(CouponCell)
Vue.use(CouponList)
Vue.use(Dialog);
// 配置路由守卫,在每次路由跳转前会执行的代码
router.beforeEach((to, from, next) => {
    // 从本地存储中获取token认证信息，需要和登陆代码相匹配
    let token = window.localStorage.getItem('authToken')
        // 判断要去的页面是否需要登录认证
    if (to.meta.requierAuth) {
        if (token) {
            // 有认证token信息，放行
            next()
        } else {
            // 没有token,重定向到登录页面，并携带上要访问的页面路径
            next({
                path: '/login',
                query: {
                    redirect: to.fullPath
                }
            })
        }
    } else {
        // 不需要认证直接放行
        next()
    }
})
new Vue({
    router,
    store,
    render: h => h(App),
    beforeCreate() {
        Vue.prototype.$bus = this
    },
    mounted() {
        this.$bus.$hotel = []
    }
}).$mount('#app')